﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {        
        if (tbMaAnToan.Value.ToLower() == Session["capcha"].ToString())
            args.IsValid = true;
        else
            args.IsValid = false;
    }
    protected void cbAgree_CheckedChanged(object sender, EventArgs e)
    {
        btnTaoTK.Enabled = cbAgree.Checked;
       
        tbMatKhau.Attributes.Add("value", tbMatKhau.Text);
        tbXNMatKhau.Attributes.Add("value", tbXNMatKhau.Text);
    }   
    protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args)
    {
        string str = args.Value;
        args.IsValid = true;
        if(str.Equals(""))
            return;
        DateTime dt;
        try
        {
            IFormatProvider format = new System.Globalization.CultureInfo("fr-FR");
            dt = DateTime.Parse(str, format);
        }
        catch
        {
            args.IsValid = false;
        }
    }
    protected void btnTaoTK_Click1(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            ImageCapCha.ImageUrl = "";
            ImageCapCha.ImageUrl = "ImageCapcha.aspx";
            DateTime ngaySinh = new DateTime();
            IFormatProvider format = new System.Globalization.CultureInfo("fr-FR");
            if (!tbNgaySinh.Value.Equals(""))
                ngaySinh = DateTime.Parse(tbNgaySinh.Value, format);
            else
                ngaySinh = new DateTime(1990, 1, 1);
            if (DBAccess.TaoTaiKhoan(tbTenDangNhap.Value, MyFunction.MahoaMatKhau(tbMatKhau.Text), tbTen.Value, int.Parse(ddNoiSinh.SelectedValue), tbMobile.Value, tbMobile.Value, tbEmail.Value, tbWebsite.Value, tbCMND.Value, ngaySinh, 1, tbLinkAvarta.Value, int.Parse(ddNganHang.SelectedValue), tbSoTaiKhoan.Value) > 0)
            {
                Thu t = new Thu();
                t.NgayGui = DateTime.Now;
                t.NguoiGui = "Administrator";
                t.NguoiNhan = tbTenDangNhap.Value;
                t.TieuDe = "Thông báo";
                t.NoiDung = (string)GetGlobalResourceObject("Text", "ChaoMung");
                t.OpenID = false;
                t.Email = "";
                DBAccess.GuiThu(t);
            }
        }
        else       
            tbMatKhau.Focus();
    }
    protected void CustomValidator3_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (-1 == DBAccess.ktTaiKhoan(tbTenDangNhap.Value, ""))
            args.IsValid = true;
        else
            args.IsValid = false;
    }
    protected void refreshCapcha(object sender, ImageClickEventArgs e)
    {
        ImageCapCha.ImageUrl = "";
        ImageCapCha.ImageUrl = "ImageCapcha.aspx";
    }
}